# Hey Emacs, this is a -*- makefile -*-
#
# Copyright (C) 2012 Felix Ruess <felix.ruess@gmail.com>


#
# This is the common Makefile for finding the arm compiler and OpenOcd
# for bare metal systems like on the ARM7TDMI, cortex M3/4

#
# try to pick up the compiler from the path
#
CC   = $(shell which arm-none-eabi-gcc)
LD   = $(shell which arm-none-eabi-gcc)
AR   = $(shell which arm-none-eabi-ar)
CP   = $(shell which arm-none-eabi-objcopy)
DMP  = $(shell which arm-none-eabi-objdump)
NM   = $(shell which arm-none-eabi-nm)
SIZE = $(shell which arm-none-eabi-size)
GDB  = $(shell which arm-none-eabi-gdb)
TOOLCHAIN_DIR=$(shell dirname `which arm-none-eabi-gcc`)
GCC_LIB_DIR=$(TOOLCHAIN_DIR)/../arm-none-eabi/lib

#
# if not found in path, try the paparazzi toolchain in /opt
#
ifeq ($(CC),)
TOOLCHAIN=$(shell find -L /opt/paparazzi/arm-multilib -maxdepth 1 -type d -name arm-none-eabi 2>/dev/null | head -n 1)
ifneq ($(TOOLCHAIN),)
TOOLCHAIN_DIR=$(shell dirname $(TOOLCHAIN))
GCC_BIN_DIR=$(TOOLCHAIN_DIR)/bin
GCC_LIB_DIR=$(TOOLCHAIN_DIR)/arm-none-eabi/lib

# Define programs and commands.
GCC_BIN_PREFIX=$(GCC_BIN_DIR)/arm-none-eabi
CC   = $(GCC_BIN_PREFIX)-gcc
LD   = $(GCC_BIN_PREFIX)-gcc
AR   = $(GCC_BIN_PREFIX)-ar
CP   = $(GCC_BIN_PREFIX)-objcopy
DMP  = $(GCC_BIN_PREFIX)-objdump
NM   = $(GCC_BIN_PREFIX)-nm
SIZE = $(GCC_BIN_PREFIX)-size
GDB  = $(GCC_BIN_PREFIX)-gdb
else
# toolchain not found...
endif
endif


# some general commands
RM = rm
